﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.States;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class StateRepositoryTest : RepositoryTestsBase<State>
    {
       string name = "State Name";

       public override System.Linq.Expressions.Expression<Func<State, bool>> FilterExpression
        {
            get { return a => a.Name == name; }
        }

        public override System.Linq.Expressions.Expression<Func<State, Guid>> OrderByExpression
        {
            get { return a => a.StateId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindState_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IStateRepository repository = new StateRepository(context,traceManager);

            //Act
            repository.FindState(null);
        }
			
		[TestMethod()]
        public void FindState_Invoke_InvalidStateNameReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IStateRepository repository = new StateRepository(context, traceManager);

			string invalidName = "invalid name";
            StateNameSpecification spec = new StateNameSpecification(invalidName);

            //Act
            State state = repository.FindState(spec);

            //Assert
            Assert.IsNull(state);
        }
		
        [TestMethod()]
        public void FindStateByStateName_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IStateRepository repository = new StateRepository(context, traceManager);

            StateNameSpecification spec = new StateNameSpecification(name);

            //Act
            State state = repository.FindState(spec);

            //Assert
            Assert.IsNotNull(state);
        }
    }
}
